import { Component, OnInit, Input} from '@angular/core';
import { GetPathService } from '../../../get-path.service';
import { TipService, ModalTipService, ModalService ,HttpService} from 'itcloud-plugin';


@Component({
  selector: 'app-view-receiver',
  templateUrl: './view-receiver.component.html',
  styleUrls: ['./view-receiver.component.css']
})
export class ViewReceiverComponent implements OnInit {
  @Input() handler;
  @Input() data;
  public fileId:any;
  public infoData:any={};
  public dataReceiverList:any;
  public fileTodoAtts:any=[];
  constructor( private GetPathService: GetPathService,
                private http: HttpService,
               private tipService: TipService,
  ) { }

  requestView() {
    this.http.getData({
      url: this.GetPathService.AjaxPath.bulletinServer+`/mineTodo/findMineTodoById?id=${this.data.datalist.userId}`,
    }).subscribe(res => {
      this.infoData=res['result'].info;
      this.fileTodoAtts=res['result'].todoAtts;
      console.log(this.infoData)
      console.log(this.fileTodoAtts)
    }, err => {
      console.log(err.returnMessage)
    });
  }
  /*驳回*/
  reject(){
    this.http.getData({
      url: this.GetPathService.AjaxPath.bulletinServer+`/mineTodo/udateStatus?id=${this.data.datalist.userId}&type=${this.data.dataRequest.infoList.infoType}&status=${this.data.dataRequest.infoList.infoStatus}`,
    }).subscribe(res => {
        this.tipService.show({
            type: 'success',
            title: '驳回成功！',
        });
        this.handler&& this.handler();
    }, err => {
      console.log(err.returnMessage)
    });
  }

  closeDrawer() {
    this.handler&& this.handler();
  }

  openData(){
    this.dataReceiverList =this.data.datalist;

  }
  timeStamp(timestamp){
    let Y,M,D,h,m,s;
    let date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    //var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
    h = (date.getHours() < 10 ? '0'+ date.getHours() : date.getHours()) + ':';
    m = (date.getMinutes() < 10 ? '0'+ date.getMinutes() : date.getMinutes()) + ':';
    s = (date.getSeconds()< 10 ? '0'+ date.getSeconds() : date.getSeconds());
    return Y+M+D+h+m+s;
  }
  /*附件大小转化*/
  conver(limit){
    let size = "";
    if( limit < 0.1 * 1024 ){ //如果小于0.1KB转化成B
      size = limit.toFixed(2) + "B";
    }else if(limit < 0.1 * 1024 * 1024 ){//如果小于0.1MB转化成KB
      size = (limit / 1024).toFixed(2) + "KB";
    }else if(limit < 0.1 * 1024 * 1024 * 1024){ //如果小于0.1GB转化成MB
      size = (limit / (1024 * 1024)).toFixed(2) + "MB";
    }else{ //其他转化成GB
      size = (limit / (1024 * 1024 * 1024)).toFixed(2) + "GB";
    }

    let sizestr = size + "";
    let len = sizestr.indexOf("\.");
    let dec = sizestr.substr(len + 1, 2);
    if(dec == "00"){//当小数点后为00时 去掉小数部分
      return sizestr.substring(0,len) + sizestr.substr(len + 3,2);
    }
    return sizestr;
  }

  ngOnInit() {
    this.openData();
    this.requestView();
  }

}
